<?php
class admin_model extends CI_Model{
      function __construct()
    {
        parent::__construct();
      }
      
      function getAllAdmin($num, $offset)
	  {
          $this->db->select('admin.*,admin_group.group_name');
          $this->db->join('admin_group','admin.group_id=admin_group.group_id','left');
          $query = $this->db->get('admin', $num, $offset);
          return $query->result();  
      }
      
      function getNumAdmin(){
          
          $this->db->join('admin_group','admin.group_id=admin_group.group_id','left');
          $query = $this->db->get('admin');
          return $query->num_rows();
      }
      
      function getAdmin($id)
	  {
          $this->db->where('admin_id',$id);
          $query = $this->db->get('admin');
          return $query->row();
      }
      
      function saveAdmin($admin_id,$data)
	  {
          if($admin_id!=0)
		  {
              $this->db->where('admin_id',$admin_id);
              if($this->db->update('admin',$data))
			  {                  
                  return true;
              }else{
                  return false;
              }
          }else{           
              if($this->db->insert('admin',$data))
			  {                 
                  return true;
              }else{
                  return false;
              }
          }
      }
      function saveDataAdmin($admin_id,$data){
          if($admin_id!=0)
		  {
              $this->db->where('admin_id',$admin_id);
              if($this->db->update('admin',$data))
			  {
                  return true;
              }else{
                  return false;
              }
          }else{         
              if($this->db->insert('admin',$data))
			  {                
                  return true;
              }else{
                  return false;
              }
          }
      }
      function delete($id)
      {
            $this->db->where('admin_id',$id);
            $query = $this->db->delete('admin');
            if($query){
                return true;
            }else{
                return false;
            }
      }
	  
      function get_list_permit()
	  {
          return $this->db->get('permission')->result();
      }
	  
      function get_list_func($PermissionID)
	  {
          $this->db->where('PermissionID',$PermissionID);
          return $this->db->get('permission_detail')->result();
      } 
      
      function get_item_permit_admin($id,$admin_id)
	  {
          $this->db->where('function_id',$id);
          $this->db->where('admin_id',$admin_id);
          $check = $this->db->get('permission_admin')->row();
          if($check){
              return true;
          }else{
              return false;
          }
      }     
      function getAllGroup(){
          return $this->db->get('admin_group')->result();
      }
}
?>
